package com.usian.article.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.usian.article.service.ApArticleConfigService;
import com.usian.common.constant.wmnews.NewAutoScanConstants;
import com.usian.model.media.pojos.WmNews;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Optional;

/**
 * ClassName: WemediaNewsAutoListener
 * Author:   WGG
 * Date:    2022-11-2022/11/24-21:44
 * Version: 1.0
 * Description:
 */
@Component
public class WemediaNewsAutoListener2 {
    @Autowired
    ApArticleConfigService apArticleConfigService;
    //kakfa监听的主题
    @KafkaListener(topics = NewAutoScanConstants.WM_NEW_AUTO_SCAN_TOPIC2)
    public void recevieMessage(ConsumerRecord<?,?> record) throws Exception {
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            Object value = record.value();
            System.out.println(value);
            System.out.println(JSON.parseObject((String)value, WmNews.class));
            //调用自动审核的方法
            apArticleConfigService.updateDown(JSON.parseObject((String)value, WmNews.class));
        }

    }
}